import request from '@/utils/request'

// 获取采集器信息
export function getInfo() {
  return request({
    url: '/apartment/ammeter',
    method: 'get',
  })
}

export function getList(data) {
  return request({
    url: '/apartment/ammeter/list',
    method: 'get',
    params: data
  })
}

// 解绑
export function unBind(id) {
  return request({
    url: `/apartment/ammeter/unbind/${id}`,
    method: 'post'
  })
}

// 绑定房间
export function bindRoom(id, roomId) {
  return request({
    url: '/apartment/ammeter/bind-room',
    method: 'put',
    params: {
      id,
      roomId
    }
  })
}

export function getUnbindList() {
  return request({
    url: '/apartment/ammeter/unbind-list',
    method: 'get',
  })
}

// 添加采集器
export function add(data) {
  return request({
    url: '/apartment/ammeter',
    method: 'post',
    data: data
  })
}

// 编辑采集器
export function edit(data) {
  return request({
    url: '/apartment/ammeter',
    method: 'put',
    data: data
  })
}

// 删除电表
export function remove(meterId) {
  return request({
    url: `/apartment/ammeter/${meterId}`,
    method: 'delete'
  })
}

// 开关闸
export function onOffChange(id, type) {
  return request({
    url: '/apartment/ammeter/on-off-change',
    method: 'post',
    params: {
      id,
      type
    }
  })
}

// 同步信息
export function sync(id) {
  return request({
    url: '/apartment/ammeter/sync-once',
    method: 'post',
    params: {
      id
    }
  })
}

// 获取用电记录列表
export function getRecordList(electricityMeterId, params) {
  // params包含: 
  // - startDate: 开始日期
  // - endDate: 结束日期
  // - dateType: 日期类型(year/month/day)
  return request({
    url: `/apartment/record/list/${electricityMeterId}`,
    method: 'get',
    params
  })
}

// 电表充值
export function recharge(electricityMeterId, money) {
  return request({
    url: `/apartment/ammeter/recharge/${electricityMeterId}`,
    method: 'post',
    data: {
      money
    }
  })
}

// 电表清零
export function reset(electricityMeterId) {
  return request({
    url: `/apartment/ammeter/reset/${electricityMeterId}`,
    method: 'post'
  })
}

// 电表开户
export function openAccount(electricityMeterId, money, accountId) {
  return request({
    url: `/apartment/ammeter/open/${electricityMeterId}`,
    method: 'post',
    data: {
      money,
      accountId
    }
  })
}

// 获取电表关联的房间列表
export function getBindRoomList(electricityMeterId, params) {
  return request({
    url: `/apartment/ammeter/bind/room/list/${electricityMeterId}`,
    method: 'get',
    params
  })
}

export default {
  getInfo,
  add,
  edit,
  onOffChange,
  unBind,
  bindRoom,
  getList,
  remove,
  getUnbindList,
  sync,
  getRecordList,
  recharge,
  reset,
  openAccount,
  getBindRoomList
}